Skip to content

Rust wrapper: fix cfg detection in build.rs for dilithium#10699

Open
holtrop-wolfssl wants to merge 1 commit into
wolfSSL:masterfrom
holtrop-wolfssl:rust-dilithium-cfg-fix
Open

Rust wrapper: fix cfg detection in build.rs for dilithium#10699
holtrop-wolfssl wants to merge 1 commit into
wolfSSL:masterfrom
holtrop-wolfssl:rust-dilithium-cfg-fix

Conversation

@holtrop-wolfssl

Copy link
Copy Markdown
Contributor

Description

Rust wrapper: fix cfg detection in build.rs for dilithium

The C library renamed dilithium to wc_mldsa, but bindgen does not pick up the backward-compatibility macros.

Testing

How did you test?

Checklist

  • added tests
  • updated/added doxygen
  • updated appropriate READMEs
  • Updated manual and documentation

The C library renamed dilithium to wc_mldsa, but bindgen does not pick
up the backward-compatibility macros.
@holtrop-wolfssl holtrop-wolfssl self-assigned this Jun 16, 2026
Copilot AI review requested due to automatic review settings June 16, 2026 14:32

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates the Rust wolfssl-wolfcrypt wrapper to detect and call wolfCrypt’s canonical ML-DSA (wc_mldsa) symbols after the C-side Dilithium rename, so Cargo cfgs and the wrapper build correctly when bindgen doesn’t emit legacy macro aliases.

Changes:

  • Updated build.rs cfg scanning to look for wc_MlDsaKey_* functions and WC_MLDSA_* constants instead of legacy wc_dilithium_* / DILITHIUM_*.
  • Switched the Rust Dilithium wrapper implementation to call the canonical wc_MlDsaKey_* API and MLDSA_*/WC_MLDSA_* constants.
  • Updated Dilithium test comments to reference MLDSA_* sizing constants.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 8 comments.

File Description
wrapper/rust/wolfssl-wolfcrypt/build.rs Fixes Cargo cfg detection by scanning for canonical ML-DSA symbols emitted by bindgen.
wrapper/rust/wolfssl-wolfcrypt/src/dilithium.rs Migrates the wrapper’s FFI calls/constants from legacy Dilithium spellings to canonical ML-DSA spellings.
wrapper/rust/wolfssl-wolfcrypt/tests/test_dilithium.rs Aligns test documentation comments with renamed ML-DSA constants.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 85 to 88
/// Required size in bytes of the seed passed to
/// [`Dilithium::generate_from_seed()`] (`DILITHIUM_SEED_SZ`).
pub const DILITHIUM_SEED_SZ: usize = sys::DILITHIUM_SEED_SZ as usize;
/// [`Dilithium::generate_from_seed()`] (`MLDSA_SEED_SZ`).
pub const MLDSA_SEED_SZ: usize = sys::MLDSA_SEED_SZ as usize;

Comment on lines 443 to 445
pub fn size(&mut self) -> Result<usize, i32> {
let rc = unsafe { sys::wc_dilithium_size(&mut self.ws_key) };
let rc = unsafe { sys::wc_MlDsaKey_Size(&mut self.ws_key) };
if rc < 0 {
Comment on lines 473 to 475
pub fn priv_size(&mut self) -> Result<usize, i32> {
let rc = unsafe { sys::wc_dilithium_priv_size(&mut self.ws_key) };
let rc = unsafe { sys::wc_MlDsaKey_PrivSize(&mut self.ws_key) };
if rc < 0 {
Comment on lines 502 to 504
pub fn pub_size(&mut self) -> Result<usize, i32> {
let rc = unsafe { sys::wc_dilithium_pub_size(&mut self.ws_key) };
let rc = unsafe { sys::wc_MlDsaKey_PubSize(&mut self.ws_key) };
if rc < 0 {
Comment on lines 639 to 644
#[cfg(dilithium_import)]
pub fn import_private(&mut self, private: &[u8]) -> Result<(), i32> {
let private_size = crate::buffer_len_to_u32(private.len())?;
let rc = unsafe {
sys::wc_dilithium_import_private(private.as_ptr(), private_size, &mut self.ws_key)
sys::wc_MlDsaKey_ImportPrivRaw(&mut self.ws_key, private.as_ptr(), private_size)
};
Comment on lines 681 to +686
#[cfg(dilithium_import)]
pub fn import_key(&mut self, private: &[u8], public: &[u8]) -> Result<(), i32> {
let private_size = crate::buffer_len_to_u32(private.len())?;
let public_size = crate::buffer_len_to_u32(public.len())?;
let rc = unsafe {
sys::wc_dilithium_import_key(
sys::wc_MlDsaKey_ImportKey(
Comment on lines 764 to 769
#[cfg(dilithium_export)]
pub fn export_private(&mut self, private: &mut [u8]) -> Result<usize, i32> {
let mut private_size = crate::buffer_len_to_u32(private.len())?;
let rc = unsafe {
sys::wc_dilithium_export_private(
sys::wc_MlDsaKey_ExportPrivRaw(
&mut self.ws_key, private.as_mut_ptr(), &mut private_size,
Comment on lines 808 to 814
#[cfg(dilithium_export)]
pub fn export_key(&mut self, private: &mut [u8], public: &mut [u8]) -> Result<(), i32> {
let mut private_size = crate::buffer_len_to_u32(private.len())?;
let mut public_size = crate::buffer_len_to_u32(public.len())?;
let rc = unsafe {
sys::wc_dilithium_export_key(
sys::wc_MlDsaKey_ExportKey(
&mut self.ws_key,
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants